//
//  ARTWatchHistoryCommonChartTitleView.m
//  ChartsDemo
//
//  Created by yunda on 2021/10/13.
//

#import "ARTWatchHistoryCommonChartTitleView.h"

@implementation ARTWatchHistoryCommonChartTitleView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-  (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (!self) {
        return nil;
    }
    // init code
    NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"ARTWatchHistoryCommonChartTitleView" owner:nil options:nil];
    // 加载nib
    self = [arrayOfViews objectAtIndex:0];
    self.frame = frame;
    CGFloat h = _helpButton.v_MaxY;
    self.v_h = h;
    
    [_helpButton whenTapped:^{
        [self helpAction];
    }];
    return self;
}

- (void)helpAction {
    if (self.helpBlock) {
        self.helpBlock();
    }
    
    NSString *title = @"";
    NSMutableAttributedString *contentAttribute = [[NSMutableAttributedString alloc]initWithString:@""];
    if (_showType == 1) {
        // 血氧饱和度
        title = FYLocalizedString(@"oxygen_warning_sp_n", @"");
        contentAttribute = [[NSMutableAttributedString alloc]initWithString:FYLocalizedString(@"sleep_watch_knowledge2", @"") attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0x222222),NSFontAttributeName:J_Font(16)}];
        [contentAttribute appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n\n" attributes:nil]];
        [contentAttribute appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@95-100%@\n",FYLocalizedString(@"sleep_watch_knowledge_ox1", @""),@"%"] attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0x222222),NSFontAttributeName:J_Font(16)}]];
        [contentAttribute appendAttributedString:[[NSAttributedString alloc] initWithString:FYLocalizedString(@"sleep_watch_knowledge_ox2", @"") attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0x222222),NSFontAttributeName:J_Font(16)}]];
        [contentAttribute appendAttributedString:[[NSAttributedString alloc] initWithString:@"89-94%\n" attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0xFF9627),NSFontAttributeName:J_Font(16)}]];
        [contentAttribute appendAttributedString:[[NSAttributedString alloc] initWithString:FYLocalizedString(@"sleep_watch_knowledge_ox3", @"") attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0x222222),NSFontAttributeName:J_Font(16)}]];
        [contentAttribute appendAttributedString:[[NSAttributedString alloc] initWithString:@"≤88%\n" attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0xE50C0C),NSFontAttributeName:J_Font(16)}]];
    }else if (_showType == 2){
        // 静息心率
        title = FYLocalizedString(@"sleep_watch_knowledge_title4", @"");
        contentAttribute = [[NSMutableAttributedString alloc]initWithString:FYLocalizedString(@"sleep_watch_knowledge4", @"") attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0x222222),NSFontAttributeName:J_Font(16)}];
        [contentAttribute appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"\n\n%@60-100 bpm\n",FYLocalizedString(@"sleep_watch_knowledge_ox1", @"")] attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0x222222),NSFontAttributeName:J_Font(14)}]];
        [contentAttribute appendAttributedString:[[NSAttributedString alloc] initWithString:FYLocalizedString(@"sleep_watch_knowledge_ox2", @"") attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0x222222),NSFontAttributeName:J_Font(14)}]];
        [contentAttribute appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n",FYLocalizedString(@"sleep_watch_tips5", @"")] attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0xFF9627),NSFontAttributeName:J_Font(14)}]];
        [contentAttribute appendAttributedString:[[NSAttributedString alloc] initWithString:FYLocalizedString(@"sleep_watch_knowledge_ox3", @"") attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0x222222),NSFontAttributeName:J_Font(14)}]];
        [contentAttribute appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n",FYLocalizedString(@"sleep_watch_tips6", @"")] attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0xE50C0C),NSFontAttributeName:J_Font(14)}]];
    }else if (_showType == 3){
        // 睡眠分期
        title = FYLocalizedString(@"sleep_watch_knowledge_title5", @"");
        contentAttribute = [[NSMutableAttributedString alloc]initWithString:FYLocalizedString(@"sleep_watch_knowledge5", @"") attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0x222222),NSFontAttributeName:J_Font(16)}];
//        [contentAttribute appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n\n提示：相关危害区间的时长和占比越小身体越健康" attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0x999999),NSFontAttributeName:J_Font(13)}]];
    }else if (_showType == 4){
        // 睡眠时间
        title = FYLocalizedString(@"sleep_watch_knowledge_title6", @"");
        contentAttribute = [[NSMutableAttributedString alloc]initWithString:FYLocalizedString(@"sleep_watch_knowledge6", @"") attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0x222222),NSFontAttributeName:J_Font(16)}];
//        [contentAttribute appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n\n提示：相关危害区间的时长和占比越小身体越健康" attributes:@{NSForegroundColorAttributeName:J_ColorFromHEX(0x999999),NSFontAttributeName:J_Font(13)}]];
    }
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.lineSpacing = 6;
    [contentAttribute addAttributes:@{NSParagraphStyleAttributeName:paragraphStyle} range:contentAttribute.rangeOfAll];
    ARTWatchHistoryAlertView *view = [[ARTWatchHistoryAlertView alloc]initWithTitle:title messageAttribute:contentAttribute];
    [view show];
}

@end
